/**
 * @description 存储数据
 * @param {*} key 指定的key
 * @param {*} value 指定的key的数据
 */
export const setStorage = (key, value) => {
  try {
    wx.setStorageSync(key, value)
  } catch (error) {
    console.error(`存储指定${key}数据发生了异常`, error)
  }
}
/**
 * @description 读取数据
 * @param {*} key 指定的key
 */
export const getStorage = (key) => {
  try {
    const value = wx.getStorageSync(key)
    return value
  } catch (error) {
    console.error(`读取指定${key}数据发生了异常`, error)
  }
}
export const removeStorage = (key) => {
  try {
    wx.removeStorageSync(key)
  } catch (error) {
    console.error(`移除指定${key}数据发生了异常`, error)
  }
}
export const clearStorage = () => {
  try {
    wx.clearStorageSync()
  } catch (error) {
    console.error('移除数据发生了异常', error)
  }
}

export const asyncSetStorage = (key, data) => {
  return new Promise((resolve) => {
    wx.setStorage({
      key,
      data,
      complete(res) {
        resolve(res)
      }
    })
  })
}

export const asyncGetStorage = (key) => {
  return new Promise((resolve) => {
    wx.getStorage({
      key,
      complete(res) {
        resolve(res)
      }
    })
  })
}

export const asyncRemoveStorage = (key) => {
  return new Promise((resolve) => {
    wx.removeStorage({
      key,
      complete(res) {
        resolve(res)
      }
    })
  })
}

export const asyncClearStorage = () => {
  return new Promise((resolve) => {
    wx.clearStorage({
      complete(res) {
        resolve(res)
      }
    })
  })
}

/**
 * @description 存储数据
 * @param {*} key 指定的key
 * @param {*} value 指定的key的数据
 */
// export const setStorage = async (key, value) => {
//   try {
//     await wx.setStorage({ key, data: value });
//   } catch (error) {
//     console.error(`存储指定${key}数据发生了异常`, error);
//   }
// }

/**
 * @description 读取数据
 * @param {*} key 指定的key
 */
// export const getStorage = async (key) => {
//   try {
//     const res = await wx.getStorage({ key });
//     return res.data;
//   } catch (error) {
//     console.error(`读取指定${key}数据发生了异常`, error);
//   }
// }

// export const removeStorage = async (key) => {
//   try {
//     await wx.removeStorage({ key });
//   } catch (error) {
//     console.error(`移除指定${key}数据发生了异常`, error);
//   }
// }

// export const clearStorage = async () => {
//   try {
//     await wx.clearStorage();
//   } catch (error) {
//     console.error('移除数据发生了异常', error);
//   }
// }
